package com.example.demo.Controller.MainController;

import com.example.demo.ServiceImpl.Ip_Table.IpTableServiceImpl;
import com.example.demo.ServiceImpl.Opus.OpusServiceImpl;
import com.example.demo.ServiceImpl.UploadFile.UploadfileServiceImpl;
import com.example.demo.ServiceImpl.User.UserServiceImpl;
import com.example.demo.Utils.Result.R;
import jakarta.annotation.Resource;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/main")
@CrossOrigin(origins = "*")
public class MainController {
    @Resource
    public UserServiceImpl userService;
    @Resource
    private UploadfileServiceImpl uploadfileService;

    @Resource
    private OpusServiceImpl opusService;

    @Resource
    private IpTableServiceImpl ipTableService;


    @GetMapping
    public R index() {
      Integer UserCount= Math.toIntExact(userService.count());
      Integer FileCount= Math.toIntExact(uploadfileService.count());
      Integer OpusCount= Math.toIntExact(opusService.count());
      Integer IpCount= Math.toIntExact(ipTableService.count());
      return R.ok().put("UserCount",UserCount)
              .put("FileCount",FileCount)
              .put("OpusCount",OpusCount)
              .put("DailyCounts",ipTableService.getDailyAccessCount())
              .put("OpusDailyCounts",opusService.getDailyCounts())
              .put("IpCount",IpCount);
    }
}
